package com.scedu.reflection;

import java.lang.reflect.Field;
import java.lang.reflect.Method;

//获得类的信息
public class Test07 {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchFieldException {
        Class<?> aClass = Class.forName("com.scedu.reflection.User");
        //获得类的名字 包名+类名
        System.out.println(aClass.getName());
        //获取类的简单名字 类名
        System.out.println(aClass.getSimpleName());

        //获取类的属性 getFields 私有属性看不到
        Field[] fields = aClass.getFields();
        for (Field field : fields) {
            System.out.println(field);
        }
        //获取类的属性 getDeclaredFields 所有属性都可以看到
        Field[] declaredFields = aClass.getDeclaredFields();
        for (Field declaredField : declaredFields) {
            System.out.println(declaredField);

        }
        //获取指定的属性
        Field name = aClass.getDeclaredField("name");
        System.out.println(name);
        //====获取类的方法;
        System.out.println("====获取类的方法=====");
        Method[] declaredMethods = aClass.getDeclaredMethods();
        for (Method declaredMethod : declaredMethods) {
            System.out.println(declaredMethod);

        }
    }
}
